package com.jiliang.common.string;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author xumqc
 * @version v_1.0.1
 * @explain 字符串校验
 * @since 2017/11/15 13:55
 */
public class StringCheckDsUtil {

    private static final Logger LOGGER = LoggerFactory.getLogger(StringCheckDsUtil.class);

    /**
     * 判断字符串是否只为数字
     */
    public static boolean isNumber(String number) {
        if (StringUtils.isBlank(number)) {
            return false;
        }
        return number.matches("[+-]?[1-9]+[0-9]*(\\.[0-9]+)?");
    }
    /**
     * 判断是否是手机号
     */
    public static boolean isMobilePhone(String mobilePhone) {
        if (StringUtils.isBlank(mobilePhone)) {
            return false;
        }
        return mobilePhone.matches("^1\\d{10}$");
    }

    public static boolean isNotBlank(String str) {
        return StringUtils.isNotBlank(str);
    }

    public static boolean isBlank(String str) {
        return StringUtils.isBlank(str);
    }

    /**
     * 字符串空返回空
     *
     * @param t
     * @param <T>
     * @return
     */
    public static <T> T isNullReturnNull(T t) {
        return t != null ? t : null;
    }

    /**
     * 字符串空返回空字符串
     *
     * @param obj
     * @return
     */
    public static String isNullReturnString(Object obj) {
        return obj != null ? obj.toString() : "";
    }

    public static void main(String[] args) {
    }
}
